<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="../../res/include/base-head.jsp"%>
	<%@include file="../../res/include/jquery-easyui.jsp"%>
  </head>
  <body>
  	<form id="data-form" class="dialog-data-form" style="width:500px;">
    	<table cellspacing="4">
    		<tbody>
    			<tr>
					<td class="field">上级菜单</td>
					<td id="parent-text" colspan="3">
						<c:if test="${parent==null}">无</c:if>
						<c:if test="${parent!=null}">${parent.name}</c:if>
					</td>
				</tr>
    			<tr>
					<td class="field">菜单名</td>
					<td><input class="field easyui-validatebox"  data-options="required:true" type="text" name="name" value="${menu.name}" maxlength="15"/></td>
				</tr>
				<tr>
					<td class="field">类型</td>
					<td>
						<select name="type">
							<option value="1"
								<c:if test="${menu != null && menu.type==1}"> selected="selected"</c:if>
							>目录</option>
							<option value="2"
								<c:if test="${menu != null && menu.type==2}"> selected="selected"</c:if>
							>叶子</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="field">状态</td>
					<td>
						<select name="status">
							<option value="1"
								<c:if test="${menu != null && menu.status==1}"> selected="selected"</c:if>
							>启用</option>
							<option value="2"
								<c:if test="${menu != null && menu.status==2}"> selected="selected"</c:if>
							>禁用</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="field">扩展/收缩</td>
					<td>
						<select name="expand">
							<option value="1"
							<c:if test="${menu != null && menu.expand==1}"> selected="selected"</c:if>
							>收缩</option>
							<option value="2"
							<c:if test="${menu != null && menu.expand==2}"> selected="selected"</c:if>
							>扩展</option>
						</select>
					</td>
				</tr>
    			<tr>
					<td class="field">URL</td>
					<td colspan="3">
						<input class="field-title easyui-validatebox" type="text" name="url" value="${menu.url}" maxlength="100"
							data-options="validType:'bytelen[0,100]',invalidMessage:'不能超过100个字节'"/>
					</td>
				</tr>
				<tr>
					<td class="field">图标</td>
					<td colspan="3">
						<input class="field-title easyui-validatebox" type="text" name="icon" value="${menu.icon}" maxlength="50"
							data-options="validType:'bytelen[0,50]',invalidMessage:'不能超过50个字节'"/>
					</td>
				</tr>
				<tr>
					<td class="field">打开图标</td>
					<td colspan="3">
						<input class="field-title easyui-validatebox" type="text" name="iconOpen" value="${menu.iconOpen}" maxlength="50"
							data-options="validType:'bytelen[0,50]',invalidMessage:'不能超过50个字节'"/>
					</td>
				</tr>
				<tr>
					<td class="field">备注</td>
					<td colspan="3">
						<textarea class="field-remark easyui-validatebox" name="remark" data-options="validType:'length[0,255]'">${menu.remark}</textarea>
					</td>
				</tr>
				<tr>
					<td colspan="4" align="center">
						<input name="menuId" type="hidden" value="${menu.menuId}"/>
						<input name="parentId" type="hidden" value="${parent.menuId}"/>
						<c:if test="${menu == null }">
							<a class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="admin.menu.doAdd();">添加</a>
						</c:if>
						<c:if test="${menu != null }">
							<a class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="admin.menu.doUpdate();">修改</a>
						</c:if>
					</td>
				</tr>
    		</tbody>
    	</table>
   	</form>
   	<script type="text/javascript">
   		Namespace('admin.menu',{
   			doAdd:function() {
   				if(!$('#data-form').form('validate')) return;
				var data=$('#data-form').form('jsonObject');
   				$.post(contextPath+'/sys/menu/add',data,function(result) {
					if(result.code==1) {
						parent.admin.menu.refreshNode(data.parentId);
						$('#data-form')[0].reset();
					} else {
						top.showInfo('添加菜单失败:'+result.msg);
					}
				},'json');
   			},
   			doUpdate:function() {
   				if(!$('#data-form').form('validate')) return;
				var data=$('#data-form').form('jsonObject');
   				$.post(contextPath+'/sys/menu/update/'+data.menuId,data,function(result) {
					if(result.code==1) {
						parent.admin.menu.refreshNode(data.parentId);
						parent.admin.menu.updateTabTitle('菜单：'+data.name);
					} else {
						top.showInfo('修改菜单失败:'+result.msg);
					}
				},'json');
   			}
   		});
   	</script>
  </body>
</html>
